package com.smy.common;
import lombok.Data;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

@Data
public class Bool<T> {
    /**
     * 当前页
     */
    private Integer current;
    /**
     * 每页显示条目
     */
    private Integer pageSize;
    /**
     * 总条数
     */
    private Integer total;
    /**
     * 根据该对象查询
     */
    private T t;
    /**
     * 根据该字段查询
     */
    private List<String> queryFields;
    /**
     * 条件查询
     */
    private StringBuilder condition = new StringBuilder();
    /**
     * 排序字段,正序为true
     */
    private LinkedHashMap<String,Boolean> sort;
    /**
     * 查询出的数据
     */
    private List<T> data;
    /**
     * 给问号赋值的集合
     */
    private List<Object> assignment = new ArrayList<>();

    public Bool<T> eq(String fieldName, Object o){
        String name = SqlHelper.getName(fieldName);
        condition.append(" and ");
        condition.append(name);
        condition.append(" = ? ");
        assignment.add(o);
        return this;
    }

    public Bool<T> lt(String fieldName, Object o){
        String name = SqlHelper.getName(fieldName);
        condition.append(" and ");
        condition.append(name);
        condition.append(" < ? ");
        assignment.add(o);
        return this;
    }
    public Bool<T> le(String fieldName, Object o){
        String name = SqlHelper.getName(fieldName);
        condition.append(" and ");
        condition.append(name);
        condition.append(" <= ? ");
        assignment.add(o);
        return this;
    }
    public Bool<T> ne(String fieldName, Object o){
        String name = SqlHelper.getName(fieldName);
        condition.append(" and ");
        condition.append(name);
        condition.append(" != ? ");
        assignment.add(o);
        return this;
    }
    public Bool<T> ge(String fieldName, Object o){
        String name = SqlHelper.getName(fieldName);
        condition.append(" and ");
        condition.append(name);
        condition.append(" >= ? ");
        assignment.add(o);
        return this;
    }
    public Bool<T> gt(String fieldName, Object o){
        String name = SqlHelper.getName(fieldName);
        condition.append(" and ");
        condition.append(name);
        condition.append(" > ? ");
        assignment.add(o);
        return this;
    }

    public String getCondition(){
        return this.condition.toString();
    }
}
